import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import { router } from 'dva';
import Image from "components/Image";
const { Link } = router;

export default (self) => [
  {
    title: 'ID',
    name: 'id',
    formItem: {
      type: 'hidden',
    }
  },
  { title: '标准头像',
    name: 'idCardPic',

    tableItem: {
      width: 50,
      render: text => {
        if (text && text !==''){
          return <Image src={text}></Image>
        }else{
          return '无'
        }
      }
    },
    // formItem: {
    //   type: 'upload',
    //   action: '/api/personIdentity/upload/originalPhoto',
    //   fileName: 'file',
    //   fileTypes: ['.png', '.jpg', '.gif'],
    //   listType: 'picture',
    //   normalize: value => {
    //     return [
    //       {
    //         uid: -1,
    //         thumbUrl: value
    //       }
    //     ];
    //   },
    //   max:1,
    //   multiple: false,
    //   rules: [
    //     {
    //       required: true,
    //       message: '请上传标准头像'
    //     }
    //   ]
    // }
  },
  {
    title: '用户名',
    name: 'realname',
    searchItem: {group: 'abc'},
    tableItem: {},
    formItem: {
      disabledOnEdit: true,
      rules: [
        {required: true, message: '请填写正确的内容'},
        {validator: (rule, value, callback)=>{
            if (!value || !(/^[\u4e00-\u9fa5]+$/.test(value))){
              callback('请填写正确的姓名(仅可使用汉字)');
            }else{
              callback();
            }
          }}
      ],
    },
  },
  {
    title: '昵称',
    name: 'nickname',
    tableItem: {},
    formItem: {},
    searchItem: {}
  }, {
    title: '性别',
    name: 'gender',
    dict: [{ code: 0, codeName: '女' }, { code: 1, codeName: '男' }],
    tableItem: { render: t=> t? '男' : '女'},
    formItem: {
      type: 'select',
      rules: [{required: true, message: '请填写正确的内容'},]
    }
  }, {
    title: '手机号',
    name: 'mobile',
    tableItem: {},
    formItem: {
      rules: [
        {required: true, message: '请填写正确的内容'},
        {
          validator: (rule, value, callback)=>{
            if (!value || !(/^1[3456789]\d{9}$/.test(value))){
              callback('请填写正确的电话号码');
            }else{
              callback();
            }
          }
        }
      ]
    },
    searchItem: {}
  },{
    title: '密码',
    name: 'password',
    formItem: {
      type: 'password',
      repeat: true,
      rulesForAdd: [{required: true, message: '请填写正确的内容'}],
   }
  },{
    title: '身份证',
    name: 'idCard',
    formItem: {
      rules: [{
        validator: (rule, value, callback)=>{
          if (value && !(/(^\d{15}$)|(^\d{17}(\d|X|x)$)/.test(value))){
            callback('请填写正确的身份证号码');
          }else{
            callback();
          }
        }
      }]
    }
  },{
    title: '状态',
    name: 'isActive',
    dict: [{ code: 0, codeName: '停用' }, { code: 1, codeName: '正常' }],
    tableItem: { render: t=> t? '正常' : '停用'},
  },
  {
    title: '操作',
    tableItem: {
      width: 180,
      render: (text, record) => {
        let activeBtn;
        if (record.isActive)
          activeBtn = <Button tooltip="停用" onClick={e =>self.handleActive(record, 0)}><Icon type="StopOutlined" antd></Icon> </Button>;
        else
          activeBtn = <Button tooltip="启用" onClick={e =>self.handleActive(record, 1)}><Icon type="CheckCircleOutlined" antd></Icon> </Button>;

      return <DataTable.Oper>
          <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
            <Icon type="edit" />
          </Button>
          <Button tooltip="删除" onClick={e => self.onDelete(record)}>
            <Icon type="trash" />
          </Button>
          {activeBtn}
        </DataTable.Oper>
      }
    }
  }
];
